package com.ly.mpayment.persist.service.downproductcode;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.DownProductCode;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class DownProductCodeServiceImpl extends AbstractService<DownProductCode, Serializable> implements IDownProductCodeService {

	@Override
	public boolean saveDownProduct(DownProductCode code) {
		if(code != null){
			this.saveOrUpdate(code);
			return true;
		}
		return false;
	}

	@Override
	public boolean updateDownProduct(DownProductCode code) {
		if(code != null){
			this.saveOrUpdate(code);
			return true;
		}
		return false;
	}

	@Override
	public DownProductCode findById(String id) {
		return this.findUnique("select d from DownProductCode d where d.proCodeId = ?", id);
	}

	@Override
	public Page<DownProductCode> findPage(Map<String, Object> parameters, int start, int pageSize) {
		return this.findPageByNamed("select d from DownProductCode d where 1 = 1 #[ and d.productCode like :productCode]# #[ and d.codeName = :codeName]#", parameters, start, pageSize);
	}

	@Override
	public DownProductCode findByCode(String code) {
		return this.findUnique("select d from DownProductCode d where d.proCodeId = ?", code);
	}

	@Override
	public List<DownProductCode> findList() {
		return this.find("select d from DownProductCode d where d.codeStatus = 1  order by codeName");
	}

}
